package site.shihuan.helpdesk.service.dao;

import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import site.shihuan.helpdesk.service.model.doc.EsKnowledge;

/**
 * EsKnowledgeDao
 *
 * @author 周世焕
 * @Date 2021/3/13 20:35
 */

public interface EsKnowledgeDao extends ElasticsearchRepository<EsKnowledge,String> {

    /**
     * 对问题和答案进行检索，问题的权重更高
     * @param tenantId
     * @param question
     * @return
     */
    @Query("{\"bool\":{\"must\":[{\"term\":{\"tenantId\":\"?0\"}}," +
            "{\"multi_match\":{\"query\":\"?1\",\"fields\":[\"question^3\",\"answer\"]}}]}}")
    Iterable<EsKnowledge> searchByQA(String tenantId,String question);

}
